<template>

	<view class="index-page with-tabbar">
		<view class="page-content">

			<!-- 个人信息 -->
			<div class="main-box">
				<!-- v-if="title === '修改昵称'" -->
				<!-- 用户昵称 -->
				<div v-if="title === '修改昵称'">
					<div class="ml-30 mr-30">
						<view class=" bg-fff p-20 mt-20 bor-r8">
							<div class="flex align-center lh-50 ">
								<div class="fontS28 color-6D">昵称</div>
								<div class="ml-20 nickName">
									<input type="text" v-model="nickName" placeholder="请输入昵称" />
								</div>
							</div>
						</view>
						<div class="mt-40 fontS24 color-6 lh-40">1.昵称非登录用户名</div>
						<div class="fontS24 color-6 lh-40">2.昵称只用于展示，可有中英文数字组成，支持2-10个字</div>
						<div class="submitBtn mt-100" @click="submitBtn">提交</div>
					</div>
				</div>
				<!-- 微信号 -->
				<div v-if="title === '微信号'">
					<div class="ml-30 mr-30">
						<view class=" bg-fff p-20 mt-20 bor-r8">
							<div class="flex align-center lh-50 ">

								<div class="fontS28 color-6D">微信号</div>
								<div class="ml-20 nickName">
									<input type="text" v-model="wxName" placeholder="请输入微信号" />
								</div>

							</div>



						</view>
						<div class="mt-40 fontS24 color-6 lh-40">请输入真实的微信号，确保{{ userInfo.userType === '02' ? '企业'
							: '牛人' }}能够搜到您。</div>

						<div class="submitBtn mt-100" @click="updateWxBtn">提交</div>
					</div>
				</div>
			</div>






		</view>
	</view>
</template>

<script>

import {
	userInfoChange,
	updateWxAccount
} from "@/api/user.js";
export default {

	data() {
		return {

			postForm: null,
			title: "",
			custom: null,
			navTop: null,
			nickName: '',
			wxName: ''
		};
	},
	computed: {
		userInfo() {
			console.log(this.$store.getters.userInfo)
			return this.$store.getters.userInfo || {};
		},


	},
	async onLoad(options) {
		let custom = wx.getMenuButtonBoundingClientRect()
		this.custom = custom
		this.navTop = custom.top - this.statusBarHeight
		this.title = options.title

	},

	methods: {
		async submitBtn() {
			const {
				code
			} = await userInfoChange({
				nickname: this.nickName
			})
			if (code === 200) {
				uni.showToast({
					title: '昵称修改已提交，请等待审核',
					icon: 'none'
				})
				uni.navigateBack({  //uni.navigateTo跳转的返回，默认1为返回上一级
					delta: 1
				});
			}

		},
		async updateWxBtn() {
			const {
				code
			} = await updateWxAccount({
				wx: this.wxName
			})
			if (code === 200) {
				uni.showToast({
					title: '微信号已修改',
					icon: 'none'
				})
				uni.navigateBack({  //uni.navigateTo跳转的返回，默认1为返回上一级
					delta: 1
				});
			}
		},
	},
};
</script>

<style lang="less" scoped>
@import url(user.less);
</style>
